﻿using System;
using System.Windows;
using Microsoft.Win32;
using GpgApi;

namespace WgpgGUI
{
    public static class Sign
    {
        public static void File(Window owner, String filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                OpenFileDialog opendialog = new OpenFileDialog
                {
                    Title = "Sign a file",   // TODO
                    Multiselect = false,
                    CheckFileExists = true,
                    CheckPathExists = true,
                    Filter = L10N.T("filter_allfiles") + "|*.*"
                };

                if (opendialog.ShowDialog(owner) != true)
                    return;

                filename = opendialog.FileName;
            }

            EncryptionDialog signdialog = new EncryptionDialog(owner)
            {
                OriginalFileName = filename,
                EncryptedFileName = filename + ".wgpg"
            };

            if (signdialog.ShowDialog() != true)
                return;

            GpgSign sign = new GpgSign(signdialog.SignatureKeyId, filename, signdialog.EncryptedFileName, signdialog.ASCIIArmored)
            {
                AskPassphrase = GUIUtils.AskPassphrase(owner)
            };

            sign.ExecuteAsync(result =>
            {
                /*if (result.Status == GpgInterfaceStatus.Success)
                    CustomMessageBox.Show(owner, L10N.T("encryption_successfull"), L10N.T("encrypt_a_file"), MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
                else
                    CustomMessageBox.Show(owner, L10N.T("encryption_failed"), L10N.T("encrypt_a_file"), MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                 * */

                // TODO
            });
        }
    }
}
